package com.sanqi.weixin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sanqi.common.annotation.Log;
import com.sanqi.common.core.controller.BaseController;
import com.sanqi.common.core.domain.AjaxResult;
import com.sanqi.common.enums.BusinessType;
import com.sanqi.weixin.domain.WxFile;
import com.sanqi.weixin.service.IWxFileService;
import com.sanqi.common.utils.poi.ExcelUtil;
import com.sanqi.common.core.page.TableDataInfo;

/**
 * 导入文件Controller
 * 
 * @author duany
 * @date 2025-09-24
 */
@RestController
@RequestMapping("/weixin/file")
public class WxFileController extends BaseController
{
    @Autowired
    private IWxFileService wxFileService;

    /**
     * 查询导入文件列表
     */
    @PreAuthorize("@ss.hasPermi('weixin:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxFile wxFile)
    {
        startPage();
        List<WxFile> list = wxFileService.selectWxFileList(wxFile);
        return getDataTable(list);
    }

    /**
     * 导出导入文件列表
     */
    @PreAuthorize("@ss.hasPermi('weixin:file:export')")
    @Log(title = "导入文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxFile wxFile)
    {
        List<WxFile> list = wxFileService.selectWxFileList(wxFile);
        ExcelUtil<WxFile> util = new ExcelUtil<WxFile>(WxFile.class);
        util.exportExcel(response, list, "导入文件数据");
    }

    /**
     * 获取导入文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('weixin:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(wxFileService.selectWxFileById(id));
    }

    /**
     * 新增导入文件
     */
    @PreAuthorize("@ss.hasPermi('weixin:file:add')")
    @Log(title = "导入文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxFile wxFile)
    {
        return toAjax(wxFileService.insertWxFile(wxFile));
    }

    /**
     * 修改导入文件
     */
    @PreAuthorize("@ss.hasPermi('weixin:file:edit')")
    @Log(title = "导入文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxFile wxFile)
    {
        return toAjax(wxFileService.updateWxFile(wxFile));
    }

    /**
     * 删除导入文件
     */
    @PreAuthorize("@ss.hasPermi('weixin:file:remove')")
    @Log(title = "导入文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(wxFileService.deleteWxFileByIds(ids));
    }
}
